package site.microkang.house.service.publicity;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import site.microkang.house.mapper.publicity.IntentionRegistPublicityMapper;
import site.microkang.house.model.publicity.entity.IntentionRegistPublicityEntity;

import java.util.List;

/**
 * @author 19565
 * @date 2021/3/15 11:11
 */
@Service
@Transactional(readOnly = true)
public class IntentionRegistPublicityService {

    @Autowired(required = false)
    private IntentionRegistPublicityMapper intentionRegistPublicityMapper;

    @Transactional(readOnly = false)
    public int externalDataInsert(IntentionRegistPublicityEntity registPublicityEntity) {
        List<IntentionRegistPublicityEntity> uniqueEntity = intentionRegistPublicityMapper.getUniqueEntity(registPublicityEntity);
        /*
        如果已经存在数据，则更新数据
         */
        if (uniqueEntity != null && uniqueEntity.size() != 0) {
            IntentionRegistPublicityEntity intentionRegistPublicityEntity = uniqueEntity.get(0);
            int update = intentionRegistPublicityMapper.updateById(intentionRegistPublicityEntity);
            return update;
        }
        int insert = intentionRegistPublicityMapper.insert(registPublicityEntity);
        return insert;
    }
}
